package org.pluslibs.framework.swingplus.utils.replace;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.swing.ImageIcon;

@Deprecated()
// Replace all uses of this class with io-plus
public class FileUtils extends org.apache.commons.io.FileUtils {

    public static String readInputStreamToString(InputStream resourceAsStream) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream));
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
        }

        br.close();
        return sb.toString();
    }

    public static String readFileOnClassPathToString(String string) throws IOException {
        ClassLoader cl = ClassLoader.getSystemClassLoader();
        InputStream resourceAsStream = cl.getResourceAsStream(string);
        String format = readInputStreamToString(resourceAsStream);
        return format;
    }

    public static ImageIcon createImageIcon(String path, String description) {
        java.net.URL imgURL = ClassLoader.getSystemClassLoader().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL, description);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
}
